package com.dhsc.service.impl.ywjk.qywjh.khtsxx;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dhsc.domain.jkzx.ywjk.qywjh.TjkMxVo;
import com.dhsc.domain.jkzx.ywjk.qywjh.jhmxxx.TjkYclxVo;
import com.dhsc.domain.jkzx.ywjk.qywjh.jhmxxx.YcjlmxVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.ywjk.qywjh.jhmxxx.IJhmxxxDao;
import com.dhsc.local.dao.ywjk.qywjh.khtsxx.IKhtsxxDao;
import com.dhsc.service.ywjk.qywjh.khtsxx.IKhtsxxService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: KhtsxxServiceImpl
 * @Description: 客户提示信息
 * @Author: jwj
 * @Date: 2023/11/7 11:06
 */
@Service
@Slf4j
public class KhtsxxServiceImpl implements IKhtsxxService {

    @Autowired
    private IKhtsxxDao khtsxxDao;

    @Autowired
    private IJhmxxxDao jhmxxxDao;

    @Override
    public ResponseObject queryKhtsYclx() {
        ResponseObject obj = new ResponseObject();
        try{
            List<TjkYclxVo> list = khtsxxDao.queryKhtsYclx();
            obj.setData(list);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("查询客户提示异常类型出错", e);
            throw new MyException("查询客户提示异常类型出错",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryKhtsInfo(YcjlmxVo ycjlmxVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            PageMethod.startPage(ycjlmxVo.getPage(), ycjlmxVo.getLimit());
            List<YcjlmxVo> list = khtsxxDao.queryKhtsInfo(ycjlmxVo);
            PageInfo<YcjlmxVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch(Exception e){
            log.error("查询客户提示信息出错", e);
            throw new MyException("查询客户提示信息出错",e);
        }
        return obj;
    }

    @Transactional("localTransactionManager")
    @Override
    public ResponseObject handleKhts(YcjlmxVo ycjlmxVo) {
        ResponseObject obj = new ResponseObject();
        try{
            //退回
            if(ycjlmxVo.getType()==1){
                //更新处理状态、处理人及处理时间
                TjkMxVo tjkMxVo=new TjkMxVo();
                tjkMxVo.setShuserid(ycjlmxVo.getUserid()+"");
                tjkMxVo.setShusername(ycjlmxVo.getUsername());
                tjkMxVo.setBh(ycjlmxVo.getBh());
                tjkMxVo.setJlzt("04");
                khtsxxDao.updateTjkTszt(tjkMxVo);
                //纳入考核,则要新增tkh_jk_mx
                if(!"0".equals(ycjlmxVo.getKhbz())){
                    jhmxxxDao.insertTkhJkMxFromTjkMx(tjkMxVo);
                }
            }
            //处理中
            else if(ycjlmxVo.getType()==2){
                TjkMxVo tjkMxVo=new TjkMxVo();
                tjkMxVo.setUserid(ycjlmxVo.getUserid()+"");
                tjkMxVo.setUsername(ycjlmxVo.getUsername());
                tjkMxVo.setBh(ycjlmxVo.getBh());
                tjkMxVo.setJlzt("03");
                tjkMxVo.setClsm(ycjlmxVo.getClsm());
                khtsxxDao.updateTjkTszt(tjkMxVo);
            }
            //已处理
            else if(ycjlmxVo.getType()==3){
                //更新处理状态、处理人及处理时间
                TjkMxVo tjkMxVo=new TjkMxVo();
                tjkMxVo.setUserid(ycjlmxVo.getUserid()+"");
                tjkMxVo.setUsername(ycjlmxVo.getUsername());
                tjkMxVo.setBh(ycjlmxVo.getBh());
                tjkMxVo.setJlzt("01");
                tjkMxVo.setClsm(ycjlmxVo.getClsm());
                khtsxxDao.updateTjkTszt(tjkMxVo);
            }
            obj.setStatus(200);
        }catch(Exception e){
            log.error("处理客户提示出错", e);
            throw new MyException("处理客户提示出错",e);
        }
        return obj;
    }
}
